package de.hs_heilbronn;


public class Bk {

	private int id;
	private String isbn = "123 - 0123456789";
	private String titel = "Das Buch der Beispiele";
	private String autor = "Max Mustermann";
	private String matrikel;
	private Database db = new Database();

	public Bk() {

	}

	public Bk(int id, String isbn, String titel, String autor, String matrikel) {
		this.id = id;
		this.isbn = isbn;
		this.titel = titel;
		this.autor = autor;
		this.matrikel = matrikel;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
		db.connectUpdate("UPDATE buch SET isbn='" + this.isbn + "' , titel='" + this.titel + "', autor='" + this.autor + "' WHERE id=" + this.id + ";");
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
		db.connectUpdate("UPDATE buch SET isbn='" + this.isbn + "' , titel='" + this.titel + "', autor='" + this.autor + "' WHERE id=" + this.id + ";");
	}

	public void setTitel(String titel) {
		this.titel = titel;
		db.connectUpdate("UPDATE buch SET isbn='" + this.isbn + "' , titel='" + this.titel + "', autor='" + this.autor + "' WHERE id=" + this.id + ";");
	}

	public void setAutor(String autor) {
		this.autor = autor;
		db.connectUpdate("UPDATE buch SET isbn='" + this.isbn + "' , titel='" + this.titel + "', autor='" + this.autor + "' WHERE id=" + this.id + ";");
	}

	public void setMatrikel(String matrikel) {
		if (matrikel.equals("nicht entliehen")){
			this.matrikel = null;
		} else {
			this.matrikel = matrikel;
		}

		db.connectUpdate("UPDATE buch SET isbn='" + this.isbn + "' , titel='" + this.titel + "', autor='" + this.autor + "', studentid = " + this.matrikel + " WHERE id=" + this.id + ";");
	}

	
	public String getMatrikel() {
		if (matrikel.equals("0")){
			return "nicht entliehen";
		} else {
			return matrikel;
		}

	}

	public String getIsbn() {
		return isbn;
	}

	public String getTitel() {
		return titel;
	}

	public String getAutor() {
		return autor;
	}


	public Database getDb() {
		return db;
	}

	public String delete() {
		db.connectUpdate("DELETE FROM buch WHERE id=" + this.id + ";"); 
		return "success";
	}

}
